<template>
	<view>
		<qiun-data-charts type="ring" :opts="opts" :chartData="chartData" />
		<view class="subsystem_box">
			<view class="subsystem">
				<text class="subsystem-text" v-for="item in evaluationScore.distribution">{{item}}</text>
			</view>
			<view class="subsystem-details">
				<text class='subsystem-details-text'
					style="margin: 0 16px 0 0;">发布日期：{{evaluationScore.releaseTime&&evaluationScore.releaseTime.slice(0,10)}}</text>
				<text class='subsystem-details-text'>评估周期类型：{{evaluationScore.periodStr}}</text>
				<text class='subsystem-details-text'
					style="margin: 0 16px 0 0;">发布状态：{{evaluationScore.releaseState==1?'已审核':'待审核'}}</text>
				<text class='subsystem-details-text'>平均评估分值：{{evaluationScore.averageScore}}</text>
				<text class='subsystem-details-text'
					style="margin: 0 16px 0 0;">评估人员数：{{evaluationScore.assResultDetailCount}}</text>
				<text class='subsystem-details-text'>行政区划：{{evaluationScore.areaName}}</text>
				<text class='subsystem-details-text'
					style="display: block;width: 100%;">评估周期：{{evaluationScore.evalSection}}</text>
			</view>
			<view class="subsystem_result">
				<text style="margin: 0 0 10px 0;display:inline-block;">评估结果</text>
				<u-radio-group v-model="subData.auditState" placement="row" size=35>
					<u-radio :disabled='options.status==1' activeColor="#217FFF" name='1' label="审核通过" labelSize=30
						style='width: 45%;'>
					</u-radio>
					<u-radio :disabled='options.status==1' activeColor="#217FFF" name='2' label="审核不通过" labelSize=30>
					</u-radio>
				</u-radio-group>
			</view>
			<view class="subsystem_result">
				<text style="margin: 0 0 10px 0;display:inline-block;">审核说明</text>
				<u--textarea v-model="subData.auditDesc" height=130 placeholder="请输入内容" :disabled='options.status==1'>
				</u--textarea>
			</view>
			<u-button v-if='options.status!=1' type="primary" size="large" text="提交"
				style='width:70%;margin-top: 30rpx;' @click='onSubmit'>
			</u-button>
		</view>
	</view>
</template>

<script>
	import * as api from '@/common/api/personnel.js'
	export default {
		components: {},
		data() {
			return {
				chartData: {
					series: [{
						data: []
					}]
				},
				opts: {
					rotate: false,
					rotateLock: false,
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE"],
					padding: [5, 5, 5, 5],
					dataLabel: true,
					legend: {
						show: true,
						position: "bottom",
						lineHeight: 25
					},
					title: {
						name: "",
						fontSize: 25,
						color: "#333333"
					},
					subtitle: {
						name: "评估得分",
						fontSize: 15,
						color: "#666666"
					},
					extra: {
						ring: {
							ringWidth: 30,
							activeOpacity: 0.5,
							activeRadius: 10,
							offsetAngle: 0,
							labelWidth: 15,
							border: false,
							borderWidth: 3,
							borderColor: "#FFFFFF"
						}
					}
				},
				options: {},
				pieData: [],
				evaluationScore: {
					distribution: ""
				},
				subData: {
					auditState: "",
					auditDesc: ""
				}
			}
		},
		onLoad(option) {
			this.options = option
		},
		mounted() {
			this.search()
		},
		onReady() {
			this.getServerData();
		},
		methods: {
			search() {
				// 去除字符串最后的分号
				let reg = /;$/gi
				api.default.getAssessmentDetails(this.options.resultId).then(res => {
					for (let key in res.data.data.distributeMap) {
						this.pieData.push({
							name: key,
							value: res.data.data.distributeMap[key]
						})
					}

					this.subData.auditState = res.data.data.auditState
					this.subData.auditDesc = res.data.data.auditDesc
					this.evaluationScore = res.data.data
					this.evaluationScore.distribution = this.evaluationScore.distribution.replace(reg, '').split(
						';')
					this.evaluationScore.evalTime =
						this.evaluationScore.evalTime.split(' ')[0].split('-')[0] + this.evaluationScore.evalTime
						.split(' ')[0].split('-')[1] + this.evaluationScore.evalTime.split(' ')[0].split('-')[2]
				})
			},
			// 延迟获取图表
			getServerData() {
				setTimeout(() => {
					let res = {
						series: [{
							data: this.pieData
						}]
					};
					this.opts.title.name = this.evaluationScore.averageScore
					this.chartData.series[0].data = this.pieData
				}, 1000);

			},

			onSubmit() {
				const formData = {
					id: this.options.id,
					...this.subData
				}
				api.default.getSaveAssessment(formData).then(() => {
					uni.showToast({
						title: '提交成功',
						icon: 'success',
						duration: 2000
					})
					setTimeout(() => {
						this.$goBack('./checkInformation', 5);
					}, 1000)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.subsystem_box {

		.subsystem {
			padding: 25rpx 45rpx;
			border-bottom: 1px #F1F1F1 solid;

			.subsystem-text {
				display: inline-block;
				width: 45%;
				margin: 0 16px 0 0;
			}

		}

		.subsystem-details {
			padding: 25rpx 45rpx;
			border-bottom: 1px #F1F1F1 solid;

			.subsystem-details-text {
				width: 47%;
				display: inline-block;
				padding: 5px 0;
			}
		}

		.subsystem_result {
			padding: 25rpx 45rpx;
			border-bottom: 1px #F1F1F1 solid;
		}
	}
</style>
